<template>
  <generaltable
    :headerData="headerData"
    :tableData="tableData"
    :total="total"
    @SizeChange="SizeChange"
    @CurrentChange="CurrentChange"
  >
    <template v-slot:btnSolt>
      <div class="block">
        <span class="demonstration">默认</span>
        <el-date-picker v-model="value1" type="date" placeholder="选择日期">
        </el-date-picker>
      </div>
      <div class="block">
        <span class="demonstration">默认</span>
        <el-date-picker v-model="value2" type="date" placeholder="选择日期">
        </el-date-picker>
      </div>
      <el-input></el-input>
      <el-button>搜索</el-button>
      <el-button>重置</el-button>
      <el-button @click="deleteLog()">
        清除
      </el-button>
    </template>
  </generaltable>
</template>
<script>
import { logObtain, logDelete } from "@/api/log.js";
import generaltable from "@/components/generaltable";
export default {
  name: "BusinessLog",
  data() {
    return {
      value1: "",
      value2: "",
      total: 0,
      page: 1,
      limit: 20,
      headerData: [
        {
          label: "用户",
          prop: "userName"
        },
        {
          label: "日志类型",
          prop: "logname"
        },
        {
          label: "日志名称",
          prop: "logtype"
        },
        {
          label: "时间",
          prop: "createTime"
        }
      ],
      tableData: []
    };
  },
  mounted() {
    let _self = this;
    _self.obtainLogTableData();
  },
  methods: {
    CurrentChange(val) {
      let _self = this;
      _self.page = val;
      _self.obtainLogTableData();
    },
    SizeChange(val) {
      let _self = this;
      _self.limit = val;
      _self.obtainLogTableData();
    },
    obtainLogTableData() {
      let _self = this;
      let data = {
        page: _self.page,
        limit: _self.limit,
        beginTime: "",
        logName: "",
        logType: ""
      };
      logObtain(data).then(res => {
        if (res.code == 20000) {
          _self.tableData = [];
          for (let item of res.data.records) {
            _self.tableData.push({
              className: item.className,
              createTime: item.createTime,
              id: item.id,
              logname: item.logname,
              logtype: item.logtype,
              method: item.save,
              regularMessage: item.regularMessage,
              userName: item.userName
            });
          }
          _self.total = res.data.total;
        }
      });
    },
    deleteLog() {
      let _self = this;
      logDelete().then(res => {
        if (res.code == 20000) {
          _self.obtainLogTableData();
        }
      });
    }
  },
  components: {
    generaltable
  }
};
</script>
<style scoped></style>
